const cors = require("cors");

const options = {
  origin: function (origin, callback) {
    // 允许所有来源
    callback(null, true);
    // 或者只允许特定来源
    // const allowedOrigins = ["http://localhost:5173"];
    // if (allowedOrigins.indexOf(origin) !== -1 || !origin) {
    //   callback(null, true);
    // } else {
    //   callback(new Error("Not allowed by CORS"));
    // }
  },
  methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
  credentials: true, // 允许发送 Cookie
};

module.exports = cors(options);
